package me.abel.auditing.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import me.abel.auditing.config.CustomAuditingListener;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;

import javax.persistence.EntityListeners;
import javax.persistence.MappedSuperclass;
import javax.persistence.Temporal;
import javax.persistence.Version;
import java.io.Serializable;
import java.util.Date;

import static javax.persistence.TemporalType.TIMESTAMP;

@Data
@MappedSuperclass
@EntityListeners(CustomAuditingListener.class)
public class BaseEntity implements Serializable {

    @Version
    private Long version;

    @CreatedDate
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
    @Temporal(TIMESTAMP)
    private Date createdTime;

    @LastModifiedDate
    @Temporal(TIMESTAMP)
    private Date lastUpdatedTime;

    @CreatedBy
    private String createUser;

    @LastModifiedBy
    private String updateUser;

    private String tenant;

}
